/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2022并保留所有权利。
 * Copyright 2022, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.suanfa.test.teshuawei;

import java.util.*;
import java.util.Map.Entry;

/** 
* @author 作者 Your-Name: 
* @version 创建时间：2019年8月26日 下午7:47:53 
* 类说明 
*/
public class MatchWord {

	public static void main1(String[] args) {
		// TODO 自动生成的方法存根
		Scanner scanner = new Scanner(System.in);
		
		while(scanner.hasNext()) {
			String[] strings = scanner.nextLine().split(" ");
			
			String s = strings[0];
			int len = strings.length;
			List<String> d = new ArrayList<String>();
			
			for(int i=1;i<len;i++) {
				d.add(strings[i]);
			}
			
			String ret = findLongestWord(s,d);
			System.out.println(ret);
		}
		
		scanner.close();
	}
	public static void main(String[] args) {
//		String str = "abpcplea";
//		String[] dict = new String[]{"ale", "apple", "monkey", "plea"};
		String str = "bpcplee";
		String[] dict = new String[]{"le","b","c"};
		System.out.println(findLongestWord(str, Arrays.asList(dict)));
	}
	
//	"barfoofoobarthefoobarman"
//	["bar","foo","the"]

	public static String findLongestWord(String s,List<String> d) {
		String ret = "";
		int len_l = d.size();
		int len_s = s.length();
		HashMap<String, Integer> map = new HashMap<String, Integer>();
	
		// 外层循环控制次数
		for(int k=0;k<len_l;k++) {
			int len_sub = d.get(k).length();
			int i=0,j=0;
			int count = 0;
			
			while(i<len_s&&j<len_sub) {
				if(s.charAt(i)==d.get(k).charAt(j)) {
					count++;
					i++;
					j++;
				}else {
					i++;
				}
			}
			if(j==len_sub) {
				map.put(d.get(k), count);
			}
		}
		
//		List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String,Integer>>(map.entrySet());
//		
//		Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
//
//			@Override
//			public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
//				// TODO 自动生成的方法存根
//				return o2.getKey().compareTo(o1.getKey());
//			}
//		});
		
		
		int max = Integer.MIN_VALUE;
		Set<String> keys = map.keySet();
		
		for(String key:keys) {
			if(map.get(key)>max) {
				max = map.get(key);
				ret = key;
			}else if(map.get(key)==max) {
				ret = key.compareTo(ret)<0?key:ret;
			}
		}
		
		return ret;
	}

}

